<template>
  <div>
    <p>{{ state }}</p>
    <el-button @click="addText" type="success" plain>点我添加诗句</el-button>
  </div>
</template>

<script setup>
import { useStorage } from '@vueuse/core'
import { ref } from 'vue'
const state = useStorage('text', '得即高歌失即休', sessionStorage)
const textArr = [', 多愁多恨亦悠悠, ', '今朝有酒今朝醉, ', '明日愁来明日愁']
const count = ref(0)
const addText = () => {
  if(count.value > 2) {
    alert('这是一首绝句哦!!!')
    count.value = 0
    return
  }
  state.value += textArr[count.value]
  count.value++
}
</script>
